package com.chz.SupermarketMS.dao;


import com.chz.SupermarketMS.dto.CommodityPD;
import com.chz.SupermarketMS.entities.PDetails;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PDetailsRepository extends CrudRepository<PDetails, Long> {


//     PDetails findByPDetailsId(long theId);

    @Override
     List<PDetails> findAll();

    @Query(nativeQuery = true,value = "SELECT p.pd_id as pdId, cp.commodity_id as many, p.quantity, p.amount, p.price " +
            "FROM chz.pdetails as p left join chz.commodity_p_details as cp on p.pd_id = cp.p_details_id;"
    )
    List<CommodityPD> commodityPD();

    PDetails findByPdId(long theId);
}
